﻿using System;

namespace Vbyte.DataSource.Cache
{
    /// <summary>
    /// 缓存策略实现接口
    /// </summary>
    /// <typeparam name="T">实例类型</typeparam>
    /// <typeparam name="I">标志实例的类型</typeparam>
    public interface ICachePolicy<T, I> 
        where T:class,ICacheTimeSupport, IObjectIdentification<I>, new()
        where I:class
    {
        /// <summary>
        /// 添加缓存
        /// </summary>
        /// <param name="identity">该数据的标志</param>
        void AddCache(I identity);

        /// <summary>
        /// 加载数据，如果不使用缓存则更新上次缓存时间。
        /// </summary>
        /// <param name="identity">该数据的标志</param>
        /// <param name="useCache">指示是否从缓存中加载</param>
        /// <returns></returns>
        T Load(I identity, bool useCache);

        /// <summary>
        /// 刷新缓存
        /// </summary>
        /// <param name="identity">该数据的标志</param>
        void RefreshCache(I identity);

        /// <summary>
        /// 清空缓存
        /// </summary>
        /// <param name="identity">该数据的标志</param>
        void RemoveCache(I identity);

        /// <summary>
        /// 获取或设置该缓存策略的缓存分钟数
        /// </summary>
        double CacheMinutes { get; set; }

        /// <summary>
        /// 获取或设置该缓存策略的缓存比较模式
        /// </summary>
        CacheCompareMode Mode { get; set; }
    }
}
